﻿

$(document).ready(function () {

    //Sorting

    $(".HDITable th").click(function () {

    });

    // ZEBRA STREIFEN
    $(".HDITable .row:odd").css("background", "#F5f5f5");

    //GROUP HANDLING

    //Padding
    $(".HDITable .groupHeader").each(function () {
        $(this).find("td").first().css("padding-left", $(this).attr("depth") * 10 + 7);

        $(this).find("td").first().prepend("<img src='/_layouts/images/plus.gif' border='0' class='groupToggle hide' alt='erweitern'/>");
        $(this).find("td").first().prepend("<img src='/_layouts/images/minus.gif' border='0' class='groupToggle' alt='minimieren'/>");
    });
    //Open/Close
    $(".HDITable .groupHeader").click(function () {
        var depth = $(this).attr("depth");
        $(this).find(".groupToggle").toggleClass("hide");
        var close = true;
        if ($(this).hasClass("closed"))
        { close = false; }
        $(this).toggleClass("closed");


        var closedBy = $(this).attr("rel");
        if (close) {

            var x = true
            var next = $(this).next();

            while (x) {
                if (next.attr("depth") > depth || next.hasClass("row")) {
                    if (!next.hasClass("hide")) {
                        next.addClass("hide");

                        next.attr("closedBy", closedBy);
                    }
                    next = next.next();
                } else {

                    x = false;
                }
            }
        } else {
            $("[closedBy='" + closedBy + "']").removeClass("hide");
            $("[closedBy='" + closedBy + "']").attr("closedBy", "");
        }

    });


    function init() {
        $(".HDITable .groupHeader").each(function () {
            var depth = $(this).attr("depth");

            var close = true;
            if (!$(this).hasClass("closed"))
            { close = false; }

            var closedBy = $(this).attr("rel");
            if (close) {
                $(this).find(".groupToggle").toggleClass("hide");
                var x = true
                var next = $(this).next();

                while (x) {
                    if (next.attr("depth") > depth || next.hasClass("row")) {
                        if (!next.hasClass("hide")) {
                            next.addClass("hide");

                        }
                        next.attr("closedBy", closedBy);

                        next = next.next();
                    } else {

                        x = false;
                    }
                }

            }
        });
    }
    init();




});